<!DOCTYPE html>
<html>
  <head>
    <title>注册页面.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  	<style type="text/css">
		body{
			/* 背景图片 */
			background-image:url(static/img/beij.png);
			background-repeat: no-repeat;  
			background-attachment: fixed;
			background-size: cover;  
			background-color: wheat;
		}
		#user_reg{
			font-size: 40px;
			text-align: center;
			margin-top: 200px;
		}
		form{
			width: 500px;
			margin: 40px auto auto auto;
			font-size: 25px;
		}
		input{
			height: 30px;
			width: 12em;
			margin-top: 5px;
			margin-bottom: 5px;
		}
		input[type="submit"],input[type="reset"]{
			height: 25px;
			width: 5em;
			margin-top: 5px;
			margin-left: 6px;
		}
	</style>
  </head>
  
  <script src="/static/js/jquery.min.js" type="text/javascript">


  </script>
  
 <body>
  	<div id="user_reg">用户注册</div>
	<form action="/login" method="post" name="form" >
		<table>
			<tr>
				<td>请输入账号：</td>
				<td><input type="text" id="username" name="username" placeholder="请输入账号" ></td>
				<td id="test_user"></td>
			</tr>
			<tr>
				<td>请输入密码：</td>
				<td><input type="password" id="password" name="password" placeholder="请输入密码" ></td>
				<td id="test_pw"></td>
			</tr>
			<tr>
				<td>请确认密码：</td>
				<td><input type="password" id="password2" name="password2" placeholder="请再次输入密码"></td>
				<td id="is_test_pw"></td>
			</tr>
			<tr>
				<td>请输入电话：</td>
				<td><input type="text" id="phone" name="telephone" placeholder="只能用中国地区注册" ></td>
				<td id="test_te"></td>
			</tr>
			<tr>
				<td></td>
				<td ><input type="submit" id="submit_form" value="注册" onclick="register()">
					<input type="reset" value="重置">
				</td>
			</tr>
			<tr>
				<td></td>
				<!-- 跳转页面 -->
				<td><a href="login">已有账户？登录</a>｜<a href="forget">意见反馈</a></td>
			</tr>
		</table>
	</form>
</body>
<script>
	function register(){
	    // 1 获取用户输入
	    var username = $('#username').val();
	    var password_1 = $('#password').val();
	    var password_2 = $('#password2').val();
	    var phone = $('#phone').val();
	    // 2 封装为json对象
	    var post_data = {"username":username,
	                    "password_1":password_1,
	                    "password_2":password_2,
	                    "phone":phone};
	    console.log(post_data);
        $.ajax({
            url:'http://127.0.0.1:8000/v1/users',
            type:'post',
            dataType:'json',
            data:JSON.stringify(post_data),
            contentType:'application/json',
            success:function(res){
                if(res.code==200){
                    //window.localStorage.setItem('user',res.data.token);
                    //window.location.href = login;
                    alert("注册成功")
                }else{
                    alert(res.error);
                }
            }
        })
    }
</script>
</html>